
import axios from 'axios'

export const request = axios.create({
	// baseURL: 'http://realworld.api.fed.lagounews.com'
	baseURL: 'https://conduit.productionready.io'
})

// 通过插件机制获取上下文对象
export default ({ store }) => {
	// 请求拦截器
	request.interceptors.request.use(function (config) {
		const { user } = store.state

		if (user && user.token) {
			config.headers.common.Authorization = `Token ${user.token}`
		}
		return config;
	}, function (error) {
		// Do something with request error
		return Promise.reject(error);
	});
	// 响应拦截器
	request.interceptors.response.use(function (response) {
		return response
	}, function (error) {
		// Do something with request error
		return Promise.reject(error);
	});
}

